from langchain_core.prompts import ChatPromptTemplate
from langchain_core.output_parsers import JsonOutputParser
from langchain_openai import ChatOpenAI

#模型
mode = ChatOpenAI(model_name="qwen-plus",
    base_url="https://dashscope.aliyuncs.com/compatible-mode/v1",
    api_key="sk-4f1498f1c0314ba79ea2919bd7a02c4d",
    temperature=0.7,
    streaming=True
)


prompt = ChatPromptTemplate.from_template(
    "返回JSON：{{'name':'姓名','age':'年龄'}},输入:{input}"
)

chain = prompt | mode | JsonOutputParser()

result = chain.invoke({"input":"张三今年30岁，打算结婚后回家学Java课程"})
print(result)